package com.example.controller.admin;

import com.example.common.Result;
import com.example.entity.DTO.StudentCourseDetailDTO;
import com.example.entity.StudentCourse;
import com.example.service.admin.AdminStudentCourseService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class AdminStudentCourseController {
    @Resource
    private AdminStudentCourseService adminStudentCourseService;

    /**
     * 获取全部学生选课详细信息
     */
    @GetMapping("/selectAllStudentCourse")
    public Result selectAllStudentCourse(@RequestParam(defaultValue = "") String courseName,
                                         @RequestParam(defaultValue = "") String studentName,
                                         @RequestParam(defaultValue = "") String className) {
        List<StudentCourseDetailDTO> studentCourseDetailDTOS = adminStudentCourseService.selectAllStudentCourse(courseName, studentName, className);
        return Result.success(studentCourseDetailDTOS);
    }

    /**
     * 根据课程id获取单个学生选课信息
     */
    @GetMapping("/selectStudentCourse")
    public Result selectStudentCourse(@RequestParam(defaultValue = "") Integer id) {
        StudentCourse studentCourse = adminStudentCourseService.selectStudentCourse(id);
        return Result.success(studentCourse);
    }

    /**
     * 添加学生选课信息
     */
    @PostMapping("/addStudentCourse")
    public Result addStudentCourse(@RequestBody StudentCourse studentCourse) {
        adminStudentCourseService.addStudentCourse(studentCourse);
        return Result.success();
    }

    /**
     * 更新学生选课信息
     */
    @PutMapping("/updateStudentCourse")
    public Result update(@RequestBody StudentCourse studentCourse) {
        adminStudentCourseService.updateStudentCourse(studentCourse);
        return Result.success();
    }

    /**
     * 删除学生选课信息
     */
    @DeleteMapping("/deleteStudentCourse/{id}")
    public Result deleteStudentCourse(@PathVariable Integer id) {
        adminStudentCourseService.deleteStudentCourse(id);
        return Result.success();
    }
}
